package com.prim.threadcoreknowledge.threadobjectclasscommonmethods;

/**
 * 展示线程sleep的时候不释放synchronized 的monitor
 * 等sleep时间到了以后，正常结束才释放锁
 */
public class SleepDontResealeMonitor implements Runnable {

    public static void main(String[] args) {
        SleepDontResealeMonitor sleepDontResealeMonitor = new SleepDontResealeMonitor();
        new Thread(sleepDontResealeMonitor).start();
        new Thread(sleepDontResealeMonitor).start();
    }
    @Override
    public void run() {
        syn();
    }

    private synchronized void syn() {
        System.out.println(Thread.currentThread().getName()+"获得了monitor");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+"退出了了monitor");
    }
}
